<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>测试vue3的watch</title>
  <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>
<body>
  <div id="app">{{name}}</div>
  <script>
    const {createApp, defineComponent, ref, watch, onMounted} = Vue
    const component = defineComponent({
      setup() {
        const name = ref('lihh')

        onMounted(() => {
          setTimeout(() => {
            name.value = 'lihh1'
          }, 2000)
        })
        
        watch(name, (val, oldVal) => {
          console.log(`新值: ${val}--旧值：${oldVal}`)
        })
        return {
          name
        }
      }
    })
    createApp(component).mount('#app')
  </script>
</body>
</html>